package me.firstapp.repository.bbs.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import me.firstapp.module.bbs.PointAccount;
import me.firstapp.repository.base.impl.EntityRepositoryImpl;
import me.firstapp.repository.bbs.PointAccountRepository;

@Repository
public class PointAccountRepositoryImpl extends EntityRepositoryImpl<PointAccount> implements PointAccountRepository {

	@Override
	public PointAccount findByMemberId(Long memberId, Long apiClientId) {
		StringBuilder sql = new StringBuilder(" FROM PointAccount bean WHERE 1=1 ");
		Map<String, Object> parameters = new HashMap<String, Object>();

		sql.append(" AND bean.apiClientId =:apiClientId ");
		parameters.put("apiClientId", apiClientId);
		sql.append(" AND bean.member.id=:memberId ");
		parameters.put("memberId", memberId);

		List<PointAccount> result = super.query(PointAccount.class, sql.toString(), parameters);
		return result.isEmpty() ? null : result.get(0);
	}

	@Override
	protected Class<PointAccount> getPersistentClass() {
		return PointAccount.class;
	}

}
